#ifndef EGG_FRAMEBUFFER_H
#define EGG_FRAMEBUFFER_H

#include "Texture.h"
#include "DepthBuffer.h"
#include "StateCache.h"

namespace egg{

    class FrameBuffer;
    typedef shared_ptr<FrameBuffer> FrameBufferPtr;

    class FrameBuffer{
    public:
        FrameBuffer(uint32 w,uint32 h);
        ~FrameBuffer();
        void resize(uint32 w,uint32 h);
        void attachColor(TexturePtr color);
        void setDepthTexture(TexturePtr depth);
        void setDepthBuffer(DepthBufferPtr depth);
        void setColor(uint32 slot,TexturePtr tex);
        void blitTo(FrameBufferPtr dest,bool depth);

        inline const TexturePtr& getColor(uint32 id){
            return mColors[id];
        }
        inline const DepthBufferPtr& getDepthBuffer(){
            return mDepthBuffer;
        }
        inline const TexturePtr& getDepthTexture(){
            return mDepthTexture;
        }
        inline uint32 getHeight(){
            return mHeight;
        }
        inline uint32 getWidth(){
            return mWidth;
        }
        inline uint32 getID(){
            return mID;
        }
    protected:
        void checkDimension(TexturePtr tex);
    protected:
        GLuint mID;
        uint32 mWidth;
        uint32 mHeight;
        TexturePtr mDepthTexture;
        DepthBufferPtr mDepthBuffer;
        vector<TexturePtr> mColors;
        vector<uint32> mDrawBuffers;
    };

}

#endif